package com.example.demo.optional;

import com.example.demo.mode.User;

import java.util.Optional;

/**
 * @author pengyifeng
 * @version 5.0
 * @ClassName Test3.java
 * @Description TODO
 * @createTime 2021年01月26日 19:55:00
 */
public class Test3 {
    public static void main(String[] args) {

        User user11=new User();
        user11.setName("zhangsan");
        Optional<User> user=Optional.ofNullable(user11);
        user.ifPresent((user1)-> user1.setName("xiaoming"));
        System.out.println(user11.getName());
        User user22=null;
        Optional.ofNullable(user11).orElseThrow(()->new RuntimeException("测试"));
    }
}
